
clear all 

//define folder global here

gl Inputs "$folder\1_Inputs"
gl Intermediate "$folder\2_Intermediate"
gl Outputs "$folder\3_Outputs"

********************************************************************************
********************************************************************************
**# TABLE D.3

import delimited "${Inputs}\NY_haslink.tex", clear
	
	replace v1 = v1 + "," + v2 if !mi(v2) & mi(v3)
	replace v1 = v1 + "," + v2 + "," + v3 if !mi(v2) & !mi(v3)
	drop v2 v3 
	drop if !regexm(v1, "&")
	drop if regexm(v1, "multicolumn")
	replace v1 = subinstr(v1, "\sym{", "", .)
	replace v1 = subinstr(v1, "}", "", .)
	replace v1 = subinstr(v1, "\\", "", .)
		
	split v1, parse("&")
	drop v1 
	rename v1* var*
	rename var1 label
	
	gen 	type = "co" if !mi(label)
	replace type = "se" if mi(label)
	replace type = "obs" if regexm(label, "Observations")
	
	replace label = trim(labe)
	replace label = label[_n-1] if mi(label)
	reshape long var , i(label type) j(col) string
	replace var = trim(var)
	
	gen 	name = lower(substr(subinstr(label, " ", "", .), 1, 3))
	replace name = "ren" if label=="Tract Median Rent"
	replace name = "pov" if label=="Tract Poverty Rate"
	
	order label name type col var
	isid type col name 

levelsof name, local(nams)
levelsof type, local(typs)
levelsof col, local(cols)
	
foreach nax in `nams' {
	di "`nax'"
	local id1 = "`nax'"
	
	foreach tyx in `typs' {
		di "`tyx'"
		local id2 = "`tyx'"
		
		foreach cox in `cols' {
			di "`cox'"
			local id3 = "`cox'"
		
		levelsof var if name=="`nax'" & ///
						type=="`tyx'" & ///
						col=="`cox'" , clean local(`id1'_`id2'_`id3')
		di "`id1'_`id2'_`id3'"
	}
}
}
	
texdoc init "${Outputs}/Supplementary data_Table_D3.tex", replace force 
tex {\footnotesize \begin{tabular}{l c c} \hline \toprule ///
	& \multicolumn{2}{c}{Matched to Benefits} \\

tex & (1) & (2) \\
tex \cmidrule{2-3}

tex $x Evicted 					& `evi_co_2' 	& `evi_co_3' \\
tex 							& `evi_se_2' 	& `evi_se_3' \\
tex $x Judge stringency 		& `str_co_2'	& `str_co_3' \\
tex 							& `str_se_2' 	& `str_se_3' \\
tex $x Female (predicted) 		& `fem_co_2' 	& `fem_co_3' \\
tex 							& `fem_se_2' 	& `fem_se_3' \\
tex $x Black (predicted) 		& `bla_co_2' 	& `bla_co_3' \\
tex 							& `bla_se_2' 	& `bla_se_3' \\
tex $x Hispanic (predicted) 	& `his_co_2' 	& `his_co_3' \\
tex 							& `his_se_2' 	& `his_se_3' \\
tex $x Ad damnum (1000s) 		& `amo_co_2' 	& `amo_co_3' \\
tex 							& `amo_se_2' 	& `amo_se_3' \\
tex $x Tenant without attorney 	& `ten_co_2' 	& `ten_co_3' \\
tex 							& `ten_se_2' 	& `ten_se_3' \\
tex $x Neighborhood poverty rate & `pov_co_2'	& `pov_co_3' \\
tex 							& `pov_se_2' 	& `pov_se_3' \\
tex $x Neighborhood median rent & `ren_co_2' 	& `ren_co_3' \\
tex 							& `ren_se_2' 	& `ren_se_3' \\
tex \midrule 
tex $x Observations				& `obs_obs_2' 	& `obs_obs_3' \\

tex \bottomrule \\
tex	\end{tabular} }
texdoc close



********************************************************************************
********************************************************************************
**# TABLE D.4

import delimited "${Inputs}\NY_hasexperianlink.tex", clear

	drop v2 v3 
	drop if !regexm(v1, "&")
	drop if regexm(v1, "multicolumn")
	replace v1 = subinstr(v1, "\sym{", "", .)
	replace v1 = subinstr(v1, "}", "", .)
	replace v1 = subinstr(v1, "\\", "", .)
		
	split v1, parse("&")
	drop v1 
	rename v1* var*
	rename var1 label
	
	gen 	type = "co" if !mi(label)
	replace type = "se" if mi(label)
	replace type = "obs" if regexm(label, "Observations")
	
	replace label = trim(labe)
	replace label = label[_n-1] if mi(label)
	reshape long var , i(label type) j(col) string
	replace var = trim(var)
	
	gen 	name = lower(substr(subinstr(label, " ", "", .), 1, 3))
	replace name = "ren" if label=="Tract Median Rent"
	replace name = "pov" if label=="Tract Poverty Rate"
	
	replace var = "278,875" if var=="278875" & label=="Observations"
	
	order label name type col var
	isid type col name 

levelsof name, local(nams)
levelsof type, local(typs)
levelsof col, local(cols)
	
foreach nax in `nams' {
	local id1 = "`nax'"
	
	foreach tyx in `typs' {
		local id2 = "`tyx'"
		
		foreach cox in `cols' {
			local id3 = "`cox'"
		
		levelsof var if name=="`nax'" & ///
						type=="`tyx'" & ///
						col=="`cox'" , clean local(`id1'_`id2'_`id3')
		di "`id1'_`id2'_`id3'"
	}
}
}
	
texdoc init "${Outputs}/Supplementary data_Table_D4.tex", replace force 
tex {\footnotesize \begin{tabular}{l c c} \hline \toprule ///
	& \multicolumn{2}{c}{Matched to Experian} \\

tex & (1) & (2) \\
tex \cmidrule{2-3}
tex $x Evicted 					& `evi_co_2' 	& `evi_co_3' \\
tex 							& `evi_se_2' 	& `evi_se_3' \\
tex $x Judge stringency 		& `str_co_2' 	& `str_co_3' \\
tex 							& `str_se_2' 	& `str_se_3' \\
tex $x Female (predicted)	 	& `fem_co_2'	& `fem_co_3' \\
tex 							& `fem_se_2' 	& `fem_se_3' \\
tex $x Ad damnum (1000s) 		& `amo_co_2' 	& `amo_co_3' \\
tex 							& `amo_se_2' 	& `amo_se_3' \\
tex $x Tenant without attorney 	& `ten_co_2' 	& `ten_co_3' \\
tex 							& `ten_se_2' 	& `ten_se_3' \\
tex $x Neighborhood poverty rate & `pov_co_2' 	& `pov_co_3' \\
tex 							& `pov_se_2' 	& `pov_se_3' \\
tex $x Neighborhood median rent	& `ren_co_2' 	& `ren_co_3' \\
tex 							& `ren_se_2' 	& `ren_se_3' \\
tex \midrule 
tex $x Observations				& `obs_obs_2' 	& `obs_obs_3' \\

tex \bottomrule \\
tex	\end{tabular} }
texdoc close


********************************************************************************
********************************************************************************
**# TABLE D.5

use "${Inputs}\NY_linking.dta", clear 

	gen 	name = "ben" if outcome=="Match to Benefits"
	replace name = "ssn" if outcome=="Missing SSN"
	
	gen 	cont = "yes" if descr=="Coef on Stringency, with controls" 
	replace cont = "no" if descr=="Coef on Stringency, no controls" | descr=="Coef on Stringency"
	
	gen zscore = beta / se
	gen pvalue = 2 * (1-normal(abs(zscore)))
	
	gen 	stars = "***" if pvalue < 0.01
	replace stars = "**" if pvalue < 0.05 & mi(stars)
	replace stars = "*" if pvalue < 0.1 & mi(stars)
	
	gen		numco = string(beta, "%10.4fc") + stars
	gen 	numse = "(" + string(se, "%10.4fc") + ")"
	gen 	numobs = string(N, "%10.0fc")
	
	drop beta se N zscore pvalue stars outcome descr
	reshape long num, i(name cont) j(type) string
	
	isid name cont typ
	compress
	
levelsof name, local(nams)
levelsof type, local(typs)
levelsof cont, local(cons)
	
foreach nax in `nams' {
	local id1 = "`nax'"
	
	foreach tyx in `typs' {
		local id2 = "`tyx'"
		
		foreach cox in `cons' {
			local id3 = "`cox'"
		
		levelsof num if name=="`nax'" & ///
						type=="`tyx'" & ///
						cont=="`cox'" , clean local(`id1'_`id2'_`id3')
		di "`id1'_`id2'_`id3'"
	}
}
}

texdoc init "${Outputs}/Supplementary data_Table_D5.tex", replace force 
tex {\footnotesize \begin{tabular}{l c c c c c} \hline \toprule ///
	& \multicolumn{2}{c}{Matched to Benefits} & & \multicolumn{2}{c}{Missing SSN} \\

tex & (1) & (2) & & (3) & (4) \\
tex \cmidrule{2-3} \cmidrule{5-6}
tex $x Judge stringency 		& `ben_co_no' 	& `ben_co_yes' 	& & `ssn_co_no' 	& `ssn_co_yes' \\
tex $x  				& `ben_se_no' 	& `ben_se_yes' 	& & `ssn_se_no' 	& `ssn_se_yes' \\

tex $x Controls 		& No			& Yes			& & No 				& Yes \\ 
tex \midrule
tex $x Observations 	& `ben_obs_no'	& `ben_obs_yes'	& & `ssn_obs_no'	& `ssn_obs_yes' \\


tex \bottomrule \\
tex	\end{tabular} }
texdoc close



